package com.mall.controller;

import com.mall.pageResult.PageResult;
import com.mall.pojo.SmsFlashPromotion;
import com.mall.service.FlashService;
import com.mall.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flash")
public class FlashController {

    @Autowired
    private FlashService flashService;

    /**
     * 根据活动名称分页查询
     *
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/list")
    public Result<PageResult<SmsFlashPromotion>> list(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                                      @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                                      @RequestParam(required = false) String keyword) {
        PageResult<SmsFlashPromotion> result = flashService.findByPageAndCondition(pageNum, pageSize, keyword);
        return Result.success(result, "操作成功");
    }

    /**
     * 编辑活动
     *
     * @param id
     * @param flashPromotion
     * @return
     */
    @PostMapping("/update/{id}")
    public Result<Integer> update(@PathVariable Integer id, @RequestBody SmsFlashPromotion flashPromotion) {
        Integer count = flashService.update(id, flashPromotion);
        return Result.success(count, "操作成功");
    }

    /**
     * 添加活动
     * @param flashPromotion
     * @return
     */
    @PostMapping("/create")
    public Result<Object> create(@RequestBody SmsFlashPromotion flashPromotion) {
        Integer count = flashService.create(flashPromotion);
        return Result.success(count, "操作成功");
    }

    /**
     * 删除活动
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public Result<Object> delete(@PathVariable Integer id) {
        Integer count = flashService.delete(id);
        return Result.success(count, "操作成功");
    }

    /**
     * 修改活动上下线状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    public Result<Object> updateStatus(@PathVariable Integer id,@RequestParam Integer status) {
        Integer count = flashService.updateStatus(id,status);
        return Result.success(count, "操作成功");
    }

    /**
     * todo:获取活动详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<SmsFlashPromotion> getPromotionMsg(@PathVariable Integer id){
        return Result.success(null,"操作成功");
    }
}
